package math

// 计算 array 中值的总和

func SumInt(a []int) int64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return int64(a[0])
	}

	var n = int64(a[0])
	for i := 1; i < len(a); i++ {
		n += int64(a[i])
	}

	return n
}

func SumInt64(a []int64) int64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return a[0]
	}

	var n = a[0]
	for i := 1; i < len(a); i++ {
		n += a[i]
	}

	return n
}

func SumUInt(a []uint) uint64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return uint64(a[0])
	}

	var n = uint64(a[0])
	for i := 1; i < len(a); i++ {
		n += uint64(a[i])
	}

	return n
}

func SumUInt64(a []uint64) uint64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return a[0]
	}

	var n = a[0]
	for i := 1; i < len(a); i++ {
		n += a[i]
	}

	return n
}

func SumFloat64(a []float64) float64 {
	switch len(a) {
	case 0:
		return 0
	case 1:
		return a[0]
	}

	var n = a[0]
	for i := 1; i < len(a); i++ {
		n += a[i]
	}

	return n
}
